var express = require('express');
var router = express.Router();
var util = require('../util/util');
var userDao = require('../dao/userDao');

/* users related. */
router.post('/register',function (req, res, next) {
    if(util.removeFavicon(req,res)) {
        util.logInfo(0, 'user/register', 'POST', req.body);
        userDao.add(req,res,next);
    }
});

router.post('/login',function (req, res, next) {
    if(util.removeFavicon(req,res)) {
        util.logInfo(0, 'user/login', 'POST', req.body);
        userDao.findOne(req,res,next);
    }
});

router.post('/logout',function (req, res, next) {
    if(util.removeFavicon(req,res)) {
        util.logInfo(0, 'user/logout', 'POST', req.body);
        userDao.clearSession(req,res,next);
    }
})

router.post('/login_wx',function (req, res, next) {
    if(util.removeFavicon(req, res)) {
        util.logInfo(0, 'user/login_wx', 'POST', req.body);
        userDao.handleWX(req, res, next);
    }
});

router.put('/client_id',function (req, res, next) {
    if(util.removeFavicon(req, res)) {
        util.logInfo(0, 'user/client_id', 'PUT', req.body);
        userDao.updateClientId(req, res, next);
    }
});

//与我有关的
router.get('/related', function (req, res, next) {
    if(util.removeFavicon(req, res)) {
        util.logInfo(0, 'user/related', 'GET', req.query);
        userDao.getRelated(req, res, next);
    }
});

module.exports = router;
